package com.zhudeshuai.zhudemolist.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.v7.app.NotificationCompat;

import com.zhudeshuai.zhudemolist.R;

/**
 * 状态栏通知的管理类
 * <p/>
 * Created by sunxu on 16/5/12.
 */
public class NotificationManagerUtil {
    private static int MAX = 20;
    private static int code = 0;

    /**
     * 展示状态栏
     *
     * @param context
     * @param pendingIntent
     * @param ContentText   设置上下文内容
     */
    public static void showNotification(Context context,
                                        int id,
                                        PendingIntent pendingIntent,
                                        int largerIcon,
                                        int smallIcon,
                                        String title,
                                        String ContentText) {

        /*PendingIntent pendingIntent = PendingIntent.getActivity(context,
                pendingIntentRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);*/

        Bitmap btm = BitmapFactory.decodeResource(context.getResources(), largerIcon);

        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        android.support.v4.app.NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
        style.bigText(ContentText);
        style.setBigContentTitle("bigContentTitle");
        style.setSummaryText("底部文字");
        Notification notification = new NotificationCompat.Builder(context)
//                .setContentTitle(title)
                .setContentText(ContentText)
//                .setTicker(ContentText)
                .setSmallIcon(smallIcon)
                .setLargeIcon(btm)
                .setPriority(Notification.PRIORITY_DEFAULT)
                .setAutoCancel(true)
                .setStyle(style)
                .setSound(Uri.parse("android.resource://com.zhudeshuai.zhudemolist/" + R.raw.atcdefault_aac))
                .setContentIntent(pendingIntent)
                .build();
        mNotificationManager.notify(id, notification); // notification
    }

    /**
     * @param context
     * @param maxCount      最多显示条数
     * @param pendingIntent
     * @param largerIcon
     * @param smallIcon
     * @param title
     * @param ContentText
     */
    public static void showNotificationMax(Context context,
                                           int maxCount,
                                           PendingIntent pendingIntent,
                                           int largerIcon,
                                           int smallIcon,
                                           String title,
                                           String ContentText) {
        MAX = maxCount;
        showNotification(context, code++, pendingIntent, largerIcon, smallIcon, title, ContentText);
        if (code >= MAX) {
            code = 0;
        }
    }
}
